package com.aaa.controller.yy;

import com.aaa.pojo.ResultBean;
import com.aaa.pojo.yy.QuSds;

import com.aaa.service.yy.QuSdsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;




@RestController
@RequestMapping("/quSds")
public class QuSdsController {

    @Autowired
    private QuSdsService quSdsService;

    @RequestMapping("/pagination")
    public ResultBean quSds(String page, String limit){
        int count = quSdsService.findCount();
        List<QuSds> all = quSdsService.findAll(page, limit);

        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setCount(count);
        resultBean.setData(all);
        return  resultBean;

    }

    @RequestMapping("/insert")
    public ResultBean quSdsInsert(QuSds quSds){
        //System.out.println(quSds);
        quSds.setCreateTime(new Date());
        //quSds.setCreateBy("feng");
        int insert = quSdsService.insert(quSds);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setData(quSds);
        resultBean.setCount(insert);
        //String s = JSON.toJSONString(resultBean);
        return resultBean;
    }

    @RequestMapping("/update")
    public ResultBean quSdsUpdate(QuSds quSds){
        //System.out.println(quSds);
        int update = quSdsService.update(quSds);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setData(quSds);
        resultBean.setCount(update);
        //String s = JSON.toJSONString(resultBean);
        return resultBean;
    }


    @RequestMapping("/delete")
    public ResultBean quSdsDelete(@RequestParam("idList") List<String> idList){
        //System.out.println(quSds);
        int delete = quSdsService.delete(idList);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        //String s = JSON.toJSONString(resultBean);
        return resultBean;
    }

    @RequestMapping("/fuzzyQuestionAndCreatBy")
    public ResultBean quSdsUpdate( String question,String createBy,String page, String limit){
        //System.out.println(quSds);
        int count = quSdsService.findCount();
        List<QuSds> quSds = quSdsService.fuzzyQuestionAndCreatBy(question, createBy,page,limit);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setData(quSds);
        resultBean.setCount(count);
        //String s = JSON.toJSONString(resultBean);
        return resultBean;
    }
    @RequestMapping({"toShowQuestionSds.do"})
    public ModelAndView toShowQuestionSds(ModelAndView modelAndView) {
        modelAndView.setViewName("QuSds");
        return modelAndView;

    }
    @RequestMapping({"toShowPlanSds.do"})
    public ModelAndView toShowPlanSds(ModelAndView modelAndView) {
        modelAndView.setViewName("PlanSds");
        return modelAndView;

    }
    @RequestMapping({"toShowResultSds.do"})
    public ModelAndView toShowResultSds(ModelAndView modelAndView) {
        modelAndView.setViewName("ResultSds");
        return modelAndView;

    }
    @RequestMapping({"toShowFormSds.do"})
    public ModelAndView toShowFormSds(ModelAndView modelAndView) {
        modelAndView.setViewName("showFormSds");
        return modelAndView;

    }
}

